<?php

namespace app\index\controller\tan;

use think\Controller;
use think\Request;
use app\index\model\tan\CardBalanceLog as CBL;
use think\Session;
use \app\index\controller\decorator as de;
class Cardbalancelog extends Controller
{
    protected $rule =[
        "startdate"  =>"date",
        "enddate"=>"date",
        'day'=>'number'
    ];
    /**
     * 显示消费记录
     * @param CBL $Cardbalancelog   收支明细model
     * @param Request $Request
     * @return array
     */
    public function index(CBL $Cardbalancelog, Request $Request)
    {
//        $this->error("sdfsdf",null ,['asdf']);
//        $this->success("adf");
        $bool=$this->validate($Request->post(),$this->rule);
        if($bool !== true){
            ReturnData::err(10011,$bool);
        }
        if(Session::get("user.is_shop") > 0){
            $id = Session::get("user.id");
        }else{
            $id = $Request->post("store_id");
        }
        if(empty($id)){
            ReturnData::err(10099,'请告诉我你要查看的店铺');
        }
        ReturnData::ok( $Cardbalancelog->SearchShow(Eliminate::E($Request->post(), $this->rule)  ,$id ) );
    }


    /**
     * 显示创建资源表单页.
     *
     * @return \think\Response
     */
    public function create()
    {
        //
    }

    /**
     *
     * @param  \think\Request  $request
     * @return \think\Response
     */
    public function save(Request $request)
    {
        exit("暂时无银行接口或支付宝接口");
        de\Decorator::setobjcet(new de\Cardbalancelog([
            "user_id"=> Session::get("user.id"),
            "before_balance"=>5454.1,
            "money"=>23,
            "after_balance"=>324,
            "operating"=>0,
            "state"=>0,
            "createtime"=>date("Y-m-d"),
            "batchcode"=> md5(time(). rand()),
            "out_trade_no"=> md5(time(). rand()),
        ]));

        de\Decorator::before();
        $x=true;
        /**
         * 因为没有接口。暂时就这样
         * 这里面的代码写调用银行接口，返回状态给after。
         */
//        Db::table()->where([])
        
        
        ReturnData::exit_(de\Decorator::after($x),10012);
        
    }

    /**
     * 显示指定的资源
     *
     * @param  int  $id
     * @return \think\Response
     */
    public function read($id)
    {
        //
    }

    /**
     * 显示编辑资源表单页.
     *
     * @param  int  $id
     * @return \think\Response
     */
    public function edit($id)
    {
        //
    }

    /**
     * 保存更新的资源
     *
     * @param  \think\Request  $request
     * @param  int  $id
     * @return \think\Response
     */
    public function update(Request $request, $id)
    {
        //
    }

    /**
     * 删除指定资源
     *
     * @param  int  $id
     * @return \think\Response
     */
    public function delete($id)
    {
        //
    }
}
